package cn.wk.service.impl;

import cn.wk.domain.TenantType;
import cn.wk.mapper.TenantTypeMapper;
import cn.wk.query.TenantTypeQuery;
import cn.wk.service.ITenantTypeService;
import cn.wk.util.PageList;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 租户(机构)类型表 服务实现类
 * </p>
 *
 * @author wk
 * @since 2021-03-02
 */
@Service
public class TenantTypeServiceImpl extends ServiceImpl<TenantTypeMapper, TenantType> implements ITenantTypeService {

    @Autowired
    private TenantTypeMapper tenantTypeMapper;

    /**
     * 高级查询
     * @param query
     * @return
     */
    @Override
    public PageList<TenantType> findByKeyword(TenantTypeQuery query) {
        String keyword = query.getKeyword();
        Wrapper wrapper = null;
        //判断关键字是否为null
        if(StringUtils.isNotBlank(keyword)){
            wrapper = Condition.wrapper();
            //高级查询名字和描述
            wrapper.like("name",keyword).or().like("description",keyword);
        }
        Page<TenantType> page = new Page<TenantType>(query.getPage(), query.getRows());
        List list = tenantTypeMapper.selectPage(page, wrapper);
        return new PageList<TenantType>(page.getTotal(),list);
    }

}
